import math
def sum(a,b):
    return (a+b)
def sub(a,b):
    return (a-b)
def mul(a,b):
    return (a*b)
def div(a,b):
    return (a/b)
def power(a,b):
    return (a**b)
def logself(a,b):
    return math.log(a,b)
def factorialself(n):
    result = 1
    for i in range(1,n+1):
        result = i*result
    return (result)
while 1:
    a = int(input("请输入a："))
    operation = input("选择操作 + — * / ** log ! sin cos tan \n")
    if operation == "+":
        b = int(input("请输入b："))
        print(" a + b = ", sum(a, b))
    elif operation == "-":
        b = int(input("请输入b："))
        print(" a - b = ", sub(a, b))
    elif operation == "*":
        b = int(input("请输入b："))
        print(" a * b = ", mul(a, b))
    elif operation == "/":
        b = int(input("请输入b："))
        while b == 0:
            print("除数不能为零\n")
            b = int(input("请重新输入b："))
        print(" a / b = ", div(a, b))
    elif operation == "**":
        b = int(input("请输入b："))
        print(" a ** b = ", power(a, b))
    elif operation == "log":
        if a <= 0:
            print("底数只能为正数\n")
            continue
        else:
            b = int(input("请输入b："))
            while b <= 0:
                print("错误，只有正数才可以求对数\n")
                b = int(input("请重新输入b："))
        print("log a b = ", logself(b, a))
    elif operation == "!":
        print(" a!= ", factorialself(a))
    elif operation == "sin":
        print("sin(a) =",math.sin(a))
    elif operation == "cos":
        print("cos(a) =",math.cos(a))
    elif operation == "tan":
        print("tan(a) =",math.tan(a))
    flag = int(input("是否继续,是请输入1，否请输入0\n"))
    if flag == 0:
        break
